package com.health.home.controller;

import com.health.common.core.utils.StringUtils;
import com.health.home.domain.po.TnewsCategoryPo;
import com.health.home.domain.vo.TnewsCategoryVo;
import com.health.home.service.TnewCategoryServcie;
import com.health.home.util.Result;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xpz
 * @date 2024/12/16 11:18
 */
@RestController
@RequestMapping("/newCategory")
public class TnewCategoryController {

    @Autowired
    private TnewCategoryServcie tnewCategoryServcie;

    /**
     * 查询所有咨询类型 对接后台管理
     *
     * @return
     */
    @PostMapping("/newCategoryList")
    public Result<List<TnewsCategoryPo>> newCategoryList(@ModelAttribute TnewsCategoryVo tnewsCategoryVo) {
        List<TnewsCategoryPo> tnewsCategoryPos = tnewCategoryServcie.newCategoryList(tnewsCategoryVo);
        return Result.success(tnewsCategoryPos);
    }

    /**
     * 添加咨询类型
     */
    @PostMapping("/newCategoryAdd")
    public Result newCategoryAdd(@ModelAttribute TnewsCategoryPo tnewsCategoryPo) {
        if (StringUtils.isEmpty(tnewsCategoryPo.getNewsCategoryName())) {
            return Result.error("资讯类型名称不能为空");
        }
        boolean save = tnewCategoryServcie.save(tnewsCategoryPo);
        return Result.success(save);
    }

    /**
     * 删除咨询类型
     */
    @PostMapping("/newCategoryDel")
    public Result newCategoryDel(Integer id) {
        boolean removeById = tnewCategoryServcie.removeById(id);
        return Result.success(removeById);
    }

    /**
     * 修改咨询类型
     */
    @PostMapping("/newCategoryUpdate")
    public Result newCategoryUpdate(@ModelAttribute TnewsCategoryPo tnewsCategoryPo)
    {
        if (StringUtils.isEmpty(tnewsCategoryPo.getNewsCategoryName())){
            return Result.error("资讯类型名称不能为空");
        }
        boolean updateById = tnewCategoryServcie.updateById(tnewsCategoryPo);
        return Result.success(updateById);
    }

}
